package me.wenlong.roomdemo

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.arch.persistence.room.Room
import android.widget.Toast
import me.wenlong.roomdemo.database.ImageEntity
import me.wenlong.roomdemo.database.OrderDatabase
import me.wenlong.roomdemo.database.OrderEntity


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val db = Room.databaseBuilder(applicationContext, OrderDatabase::class.java, "database-name").allowMainThreadQueries().build()
        db.getOrderDao().insertOrder(OrderEntity("11", 0))
        db.getImageDao().insertImage(
            arrayListOf(
                ImageEntity(1, "11", "www.baidu.com"),
                ImageEntity(2, "11", "www.baidu.com2"),
                ImageEntity(3, "11", "www.baidu.com3"),
                ImageEntity(4, "11", "www.baidu.com4")
            )
        )
//        Toast.makeText(this@MainActivity, db.getOrderDao().getAllOrder().toString(), Toast.LENGTH_SHORT).show()
        Toast.makeText(this@MainActivity, db.getImageDao().getAllImage().toString(), Toast.LENGTH_LONG).show()

    }
}
